package com.housekeeping.housekeeping.advertisingmanagement.controller.ad;/*
 * @author  pyh
 * @date  2021/1/19 0019 上午 10:59
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.advertisingmanagement.entity.AdMessages;
import com.housekeeping.housekeeping.advertisingmanagement.service.AdMessagesService;
import com.housekeeping.housekeeping.advertisingmanagement.service.impl.AdMessagesServiceImpl;
import com.housekeeping.housekeeping.advertisingmanagement.utils.Page;
import com.housekeeping.housekeeping.advertisingmanagement.utils.ResponseEntitys;
import com.housekeeping.housekeeping.advertisingmanagement.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 分页查询
 * 1、先获取page 和size
 * 2、
 */
@WebServlet("/ad/list")
public class ListController extends HttpServlet {
    private AdMessagesService ams = new AdMessagesServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int page = Integer.parseInt(req.getParameter("page"));
        int size = Integer.parseInt(req.getParameter("size"));
        ResponseEntitys<Page<AdMessages>> entity = null;
        try {
            Page<AdMessages> list = ams.list(page, size);
            entity = ResponseEntitys.success(list);
        } catch (SQLException throwables) {
            entity = ResponseEntitys.error(40009, "系统异常! 请稍后再试");
        }
        ResponseUtils.resp(resp,entity);
    }
}
